using BCW.Friends;
using UnityEngine;

public class PixelmonGameMode : TeamGameMode
{
	public override void StartRound()
	{
		base.StartRound();
		if (PixelmonController.instance != null)
		{
			PixelmonController.instance.GetInfoFromMaster(PlayerBehavior.MyPlayer);
		}
		TDMController.instance.SetStartPVP(true);
		SpawnPointChief.SpawnPoint randomPointForTDM = SpawnPointChief.instance.getRandomPointForTDM(PlayerBehavior.MyPlayer);
		CoroutineRunner.Instance.StartCoroutine(ManagerPreloadingSectors.thisScript.LoadSectorsNearPoint(new Vector2(randomPointForTDM.position.x, randomPointForTDM.position.z)));
		CoroutineRunner.Instance.StartCoroutine(PVPManager.instance.WaitForSectorsLoad(delegate
		{
			BCWDebug.LogError("StartTeamMatch ", "Debug Tdm");
			TDMController.instance.SetStartPVP(true);
			PlayerBehavior.MyPlayer.FirstSpawn(2f);
			CoroutineRunner.Invoke(2.5f, delegate
			{
				GameInfoWindow.instance.HideInterface();
				MapWindow.instance.gameObject.SetActive(true);
				GameController.instance.showWindowGame();
			});
		}));
	}

	public override void RestartRound()
	{
		base.RestartRound();
		TDMController.instance.WaitTeamAndSpawnPointOnRestart(RestartPixmon);
	}

	private void RestartPixmon()
	{
		CoroutineRunner.Instance.StartCoroutine(TDMController.instance.WaitRestartTDM());
		if (PixelmonController.instance != null)
		{
			PixelmonController.instance.GetInfoFromMaster(PlayerBehavior.MyPlayer);
		}
		if (FriendsUIGame.instance != null)
		{
			FriendsUIGame.instance.CleanInvitePlayer();
		}
	}

	public override void EndRound()
	{
		PixelmonController.instance.EndGame();
	}

	public override TDMResult GetRoundResult()
	{
		if (PixelmonController.instance != null && PixelmonController.instance.winnerTeam != TDMResult.None)
		{
			return PixelmonController.instance.winnerTeam;
		}
		return base.GetRoundResult();
	}
}
